package api

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto"
	"api-gateway/handler/request"
	"api-gateway/handler/resp"
	"github.com/gin-gonic/gin"
)

// 短信
func SendSms(c *gin.Context) {
	var req request.SendSmsReq
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数有误", err.Error())
		return
	}

	sms, err := config.HouseClient.SendSms(c, &__.SendSmsReq{
		Mobile: req.Mobile,
	})
	if err != nil {
		resp.Error(c, 500, "服务端错误", err.Error())
		return
	}

	resp.Success(c, "短信发送成功", sms)

}

// 客户注册
func CustomerLogin(c *gin.Context) {
	var req request.CustomerLoginReq
	if err := c.ShouldBind(&req); err != nil {
		resp.Error(c, 400, "参数有误", err.Error())
		return
	}

	customerLogin, err := config.HouseClient.CustomerLogin(c, &__.CustomerLoginReq{
		Mobile:   req.Mobile,
		Password: req.Password,
		SmsCode:  req.SmsCode,
	})
	if err != nil {
		resp.Error(c, 500, "服务端错误", err.Error())
		return
	}

	resp.Success(c, "客户登录成功", customerLogin)

}
